/*
题目：七进制数
给定一个整数 num，将其转化为 7 进制，并以字符串形式输出。
 */
public class ConvertToBase7 {
    public String convertToBase7(int num) {
        if (num == 0)  return new String("0");
        StringBuilder sb = new StringBuilder();
        boolean isPositive = false;
        if (num < 0) {
            isPositive = true;
            num = -num;
        }
        while (num != 0) {
            sb.append(num % 7);
            num /= 7;
        }
        if (isPositive) {
            sb.append('-');
        }
        return sb.reverse().toString();
    }
}
